package cc.wsyw126.java.nowcoder.sword_offer;

import cc.wsyw126.java.lintCode.swap_two_nodes_in_linked_list.ListNode;

/**
 * Created by dp on 17/3/28.
 */
public class FindKthToTail {
    public ListNode FindKthToTail(ListNode head, int k) {
        if (head == null || k <= 0) return null;
        ListNode mid = head;
        for (int i = 0; i < k - 1; i++) {
            mid = mid.next;
            if (mid == null) {
                return null;
            }

        }
        ListNode position = head;
        while (mid.next != null) {
            mid = mid.next;
            position = position.next;
        }
        return position;
    }
}
